package com.felix.service;

import com.felix.entity.Person;
import com.felix.repository.PersonRepository;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * PersonService
 *
 * @author xjh
 * @version 1.0
 * @date 2019-05-21
 */
@Service
public class PersonService {
    @Autowired
    private PersonRepository personRepository;

    //    @Transactional(rollbackFor = RuntimeException.class)
    public void saveA() {
        ((PersonService) AopContext.currentProxy()).saveB();
    }

    @Transactional(rollbackFor = RuntimeException.class)
    public void saveB() {
        Person person1 = new Person();
        person1.setAge(18);
        person1.setName("xuejh");
        personRepository.save(person1);
        int i = 1 / 0;
        Person person2 = new Person();
        person2.setAge(19);
        person2.setName("xuejinhua");
        personRepository.save(person2);
    }
}
